// 代码高亮插件
import Vue from 'vue'
import hljs from 'highlight.js';
// 必须导入 否则没样式
// import 'highlight.js/styles/atom-one-dark-reasonable.css';
const high = {
  deep: true,
  bind: function (el, binding) {
    const targets = el.querySelectorAll('code')
    targets.forEach((target) => {
      if (binding.value) {
        target.textContent = binding.value;
      }
      hljs.highlightBlock(target);
    })
  },
//   componentUpdated: function (el, binding) {
//     const targets = el.querySelectorAll('code')
//     targets.forEach((target) => {
//       if (binding.value) {
//         target.textContent = binding.value;
//         hljs.highlightBlock(target);
//       }
//     })
//   }
}
Vue.directive('highlightjs', high)